const demoService = require('service/demo');

function* addBreathLog(next) {
	let { time, data, deviceId } = this.request.body;
	// console.log('------this.request.body-------',this.request.body)
	yield demoService.addBreathLog(time, data, deviceId);
	this.body = this.success();
	return yield next;
}


function* getBreathLog(next) {
	let { deviceId } = this.params;
	let { startTime, endTime } = this.query;
	let logs = yield demoService.getBreathLog(startTime, endTime, deviceId);
	this.body = this.success(logs);
	return yield next;
}

function* addDevice(next) {
	let { name, deviceId } = this.request.body;
	yield demoService.addDevice(name, deviceId);
	this.body = this.success();
	return yield next;
}

function* getDevices(next) {
	let { page, limit } = this.query;
	let devices = yield demoService.getDevices(page, limit);
	this.body = this.success(devices);
	return yield next;
}


function* deleteDevice(next) {
	let { id } = this.params;
	yield demoService.deleteDevice(id);
	this.body = this.success();
	return yield next;
}

module.exports = {
	addBreathLog,
	getBreathLog,
	addDevice,
	getDevices,
	deleteDevice
};